<include file="public@header"/>
</head>
<style>
    /*tr td input,tr td select{ max-width:100px;width:auto;}*/
</style>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li ><a href="{:url('Archives/visua')}">{:lang('ADMIN_VISUA_INDEX')}</a></li>
        <li><a href="{:url('Archives/archives')}">档案管理</a></li>
        <li class="active"><a href="javascript:">档案编辑</a></li>
    </ul>
    <form class="form-horizontal js-ajax-form" action="{:url('Archives/edit_post')}" method="post">
        <fieldset>
            <input type="hidden" name="tomb_id" value="{$tomb_id}">
            <input type="hidden" name="order_id" value="{$order_id}">
            <input type="hidden" name="tomb_product_id" value="{$id}">
            <input type="hidden" name="tomb_regulation" value="{$tomb_regulation}">

            <div class="p_title">
                <span class="span_title">订单详情</span>
            </div>

            <div class="control-group1-p" style="border:1px solid #e2e2e2; padding-top:20px;margin:0 20px;overflow:hidden; overflow-x:auto;">
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th>档案号</th>
                        <th>墓位编号</th>
                        <th>所在区域</th>
                        <th>具体位置</th>
                        <th>墓位状态</th>
                        <th>销售价格(元)</th>
                        <if condition="$cate_id eq '2'">
                            <th>认购面积(㎡)</th>
                        </if>
                        <th>免零金额(元)</th>
                        <th>成交价格(元)</th>
                        <th>类型</th>
                        <th>购买时间</th>
                        <th>打证时间</th>
                        <th>导购员</th>
                        <th>代理商</th>
                        <th>抵顶人</th>
                        <th>经办人</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td><input type="text" class="form-control" name="archives_sn" value="{$archives_sn|default=''}"
                                   style="width: 150px" required></td>
                        <td><input type="text" class="form-control" name="tomb_num" value="{$tomb_num|default=''}"
                                   style="width: 100px" disabled>
                            <input type="hidden" class="form-control" name="tomb_num" value="{$tomb_num|default=''}">
                        </td>
                        <td><input type="text" class="form-control" name="tomb_region" value="{$tomb_region|default=''}"
                                   style="width: 250px; height: 34px" disabled></td>
                        <td><input type="text" class="form-control" name="tomb_address" value="{$tomb_address|default=''}"
                                   style="width: 150px; height: 34px" disabled>
                        </td>
                        <td>
                            <select name="col_status" class="form-control" required  >
                                <option value="5"<if condition="$col_info.col_status eq '5'">selected</if>>购买未使用</option>
                                <option value="6"<if condition="$col_info.col_status eq '6'">selected</if>>部分安葬</option>
                                <option value="7"<if condition="$col_info.col_status eq '7'">selected</if>>全部安葬</option>
                            </select>
                        </td>
                        <td><input type="text" class="form-control selling_price" name="selling_price" value="{$selling_price|default=''}"
                                   style="width: 90px" readonly="">
                        </td>
                        <if condition="$cate_id eq '2'">
                            <td><input type="text" class="form-control subscription_area" name="subscription_area" value="{$subscription_area|default=''}"
                                       style="width: 90px" required>
                            </td>
                        </if>
                        <td><input type="text" class="form-control free_price" min="0" name="free_price" value="{$free_price|default=''}"
                                   style="width: 90px">
                        </td>
                        <td><input type="text" class="form-control closing_price" name="closing_price" value="{$closing_price|default=''}"
                                        style="width: 90px"></td>
                        <td>
                            <select name="tomb_type" class="form-control" disabled>
                                <option value="1"<if condition="$cate_id eq '1'">selected</if>>商品墓</option>
                                <option value="2"<if condition="$cate_id eq '2'">selected</if>>艺术墓</option>
                                <option value="3"<if condition="$cate_id eq '3'">selected</if>>生态墓</option>
                                <option value="4"<if condition="$cate_id eq '4'">selected</if>>节地墓</option>
                            </select>
                            <input type="hidden" class="form-control" id="tomb_type" name="tomb_type" value="{$cate_id|default=''}">
                        </td>
                        <td><input type="text" class="form-control js-date" name="closing_time" autocomplete="off"
                                   value="{$closing_time|default=''}"
                                   style="width: 105px"></td>

                        <td><input type="text" class="form-control js-date" name="dz_time" autocomplete="off"
                                   value="{$dz_time|default=''}"
                                   style="width: 105px"></td>

                        <td>
                            <select name="shoppingguide" class="form-control">
                                <option value="">请选择</option>
                                <volist name="yewu" id="vo">
                                    <option value="{$vo.id}"
                                    <if condition="$shoppingguide eq $vo.id">selected</if>
                                    >{$vo.department_name}-{$vo.user_nickname}</option>
                                </volist>
                            </select>
                        </td>
                        <td>
                            <select name="agent_user" class="form-control">
                                <option value="">请选择</option>
                                <volist name="daili" id="vo">
                                    <option value="{$vo.id}"
                                    <if condition="$agent_user eq $vo.id">selected</if>
                                    >{$vo.department_name}-{$vo.user_nickname}</option>
                                </volist>
                            </select>
                        </td>
                        <td><input type="text" class="form-control" name="reaching" value="{$reaching|default=''}"
                                   style="width: 80px;" disabled>
                        </td>
                        <td><input type="text" class="form-control"
                                   value="{$user_name}" readonly style="width: 80px" disabled></td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="p_title">
                <span class="span_title">购买人信息</span>
            </div>
            <div class="control-group1-p"
                 style="border:1px solid #e2e2e2; padding-top:20px;margin:0 20px;overflow:hidden; overflow-x:auto;">

                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th width="15%">客户账户</th>
                        <th width="8%">购买人姓名</th>
                        <th width="10%">联系电话</th>
                        <th width="8%">证件类型</th>
                        <th width="12%">身份证号</th>
                        <th width="10%">证件上传</th>
                        <th width="12%">联系地址</th>
                        <th width="10%">合同签订日期</th>
                        <th width="15%">上传签章方案</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td><input type="text" class="form-control" name="customer_account" required value="{$buyer.customer_account|default=''}"
                                   style="width: 175px" placeholder="客户身份证号码"></td>
                        <td><input type="text" class="form-control" name="buyer_name" required value="{$buyer.buyer_name|default=''}"
                                   style="width: 100px"></td>
                        <td><input type="text" class="form-control" name="buyer_phone" required value="{$buyer.buyer_phone|default=''}"
                                   style="width: 120px"></td>
                        <input type="hidden" name="customer_id" value="{$customer_id|default=''}">
                        <td>
                            <select name="cart_type" class="form-control">
                                <option value="1"
                                <if condition="$buyer.cart_type eq 1">selected</if>
                                >身份证</option>
                                <!--<option value="2"-->
                                <!--<if condition="$buyer.cart_type eq 2">selected</if>-->
                                <!--&gt;护照</option>-->
                            </select>
                        </td>
                        <td><input type="text" class="form-control" required name="cart_ID" value="{$buyer.cart_ID|default=''}"
                                   style="width: 175px"></td>
                        <td>

                            <php>$img_cer=cmf_get_image_preview_url(isset($buyer['cart_upload'])?$buyer['cart_upload']:'');</php>
                            <input type="hidden" name="cart_upload_id" id="cart_upload-file_id" value="">
                            <input type="hidden" name="cart_upload" id="cart_upload" value="{$buyer.cart_upload|default=''}">
                            <a href="javascript:gpyUploadOneImage('图片上传','#cart_upload','{$tomb_num}');">
                                <h5 class="btn btn-primary">拍照上传</h5>
                            </a>
                            <img src="{$img_cer}" onclick="parent.imagePreviewDialog(this.src);"  id="cart_upload-preview" style="cursor: pointer; width: 50px"/>

                        </td>
                        <td><input type="text" class="form-control" name="customer_address" value="{$buyer.customer_address|default=''}"
                                   style="width: 200px; height: 34px">
                        </td>
                        <td>
                            <input type="text" name="sign_time" class="form-control js-date" value="{$con_is.sign_time|default=''}" style="width: 110px;"  autocomplete="off">
                        </td>
                        <td>
                            <input type="hidden" name="contract_id" value="{$con_is.contract_id|default=''}">
                            <input type="hidden" name="contract_sn" value="{$con_is.contract_sn|default=''}">
                            <input type="text" name="contract_enclosure"  style="width: 120px;"  id="contract_enclosure-name" class="form-control" value="{$con_is.contract_enclosure_file_name|default=''}" readonly/>
                            <input type="hidden" name="contract_enclosure" id="contract_enclosure" value="{$con_is.contract_enclosure|default=''}" />
                            <input type="hidden" name="contract_enclosure_file_id" id="contract_enclosure-file_id"  value="{$con_is.contract_enclosure_file_id|default=''}"  />
                            <a class="btn btn-primary upload" href="javascript:gpyUploadOneImage('上传签章合同','#contract_enclosure','{$tomb_num}','file');">{:lang("UPLOAD")}</a>

                            <if condition="$con_is.contract_enclosure != '' ">
                                <php>$file_url=cmf_get_file_download_url(isset($con_is['contract_enclosure'])?$con_is['contract_enclosure']:'');</php>
                                <a href="{$file_url}" class="btn btn-primary" >下载</a>
                            </if>
                        </td>

                    </tr>
                    </tbody>
                </table>
            </div>
            <if condition="$cate_id != '2'">
            <div class="p_title">
                <span class="span_title">逝者信息</span>
            </div>
            <div class="control-group1-p"
                 style="border:1px solid #e2e2e2; padding-top:20px;margin:0 20px;overflow:hidden; overflow-x:auto;">
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th>逝者姓名</th>
                        <th>性别</th>
                        <th>出生日期</th>
                        <th>逝世日期</th>
                        <th>维护期起始日</th>
                        <th>落葬时间</th>
                        <th>收敛形式</th>
                        <th>类型</th>
                        <th>持证人与使用人关系</th>
                        <th>火化证明</th>
                    </tr>
                    </thead>
                    <tbody>
                    <empty name="deceased">
                        <?php
                        for ($x=0; $x<$tomb_regulation; $x++) {
                     ?>
                        <tr>
                            <td><input type="text" class="form-control" name="deceased_name[]" style="width: 100px"></td>
                            <td>
                                <select name="gender[]" class="form-control" style="width: 70px">
                                    <option value="1">男</option>
                                    <option value="2">女</option>
                                </select>
                            </td>
                            <td><input type="text" class="form-control js-date" name="date_birth[]" style="width: 105px" autocomplete="off"></td>
                            <td><input type="text" class="form-control js-date" name="date_death[]" style="width: 105px" autocomplete="off"></td>
                            <td>
                                <if condition="$x eq 0">
                                    <input type="text" class="form-control js-date" name="whq_start_date" style="width: 105px" autocomplete="off">
                                </if>
                            </td>
                            <td><input type="text" class="form-control js-datetime" name="funeral_time[]" style="width: 168px" autocomplete="off"></td>
                            <td>
                                <select name="convergence_type[]" class="form-control">
                                    <option value="1">骨灰</option>
                                    <option value="2">骨殖</option>
                                </select>
                            </td>
                            <td>
                                <select name="type[]" class="form-control" style="width: 120px">
                                    <option value="">请选择</option>
                                    <option value="1">首位安葬</option>
                                    <option value="2">合葬</option>
                                </select>
                                <input name="receptionist[]" value="" type="hidden">
                            </td>
                            <!--<td>-->
                                <!--<select name="receptionist[]" class="form-control">-->
                                    <!--<volist name="deptPer" id="vo">-->
                                        <!--<option value="{$vo.id}">{$vo.department_name}-{$vo.user_nickname}</option>-->
                                    <!--</volist>-->
                                <!--</select>-->
                            <!--</td>-->
                            <td><input type="text" class="form-control" name="relationship_users[]" value=""
                                       style="width: 160px"></td>
                            <td>
                                <php>$img_cer=cmf_get_image_preview_url(isset($vo['cremation_certificate'])?$vo['cremation_certificate']:'');</php>
                                <input type="hidden" name="cremation_certificate_file_id[]" id="thumb1-file_id" value="{$vo.cremation_certificate_file_id|default=''}">
                                <input type="hidden" name="cremation_certificate[]" id="thumb1" value="{$vo.cremation_certificate|default=''}">
                                <a href="javascript:gpyUploadOneImage('图片上传','#thumb1','{$tomb_num}');">
                                    <h5 class="btn btn-primary">拍照上传</h5>
                                </a>
                                <img src="{$img_cer}" onclick="parent.imagePreviewDialog(this.src);"  id="thumb1-preview" style="cursor: pointer; width: 50px"/>
                            </td>
                        </tr>
                        <?php
                        }
                     ?>
                    <else/>
                        <foreach name="deceased" item="vo" key="x" >
                            <tr>
                                <td><input type="hidden" class="form-control"  name="deceased_id[]" value="{$vo.deceased_id}">
                                    <input type="text" class="form-control" name="deceased_name[]"
                                           value="{$vo.deceased_name}"
                                           style="width: 100px"></td>
                                <td><select name="gender[]" class="form-control" style="width: 70px">
                                    <option value="1"
                                    <if condition="$vo.gender eq 1">selected</if>
                                    >男</option>
                                    <option value="2"
                                    <if condition="$vo.gender eq 2">selected</if>
                                    >女</option>
                                </select>
                                </td>
                                <td><input type="text" class="form-control js-date" name="date_birth[]" autocomplete="off"
                                           value="{$vo.date_birth}"
                                           style="width: 105px"></td>
                                <td><input type="text" class="form-control js-date" name="date_death[]" autocomplete="off"
                                           value="{$vo.date_death}"
                                           style="width: 105px"></td>
                                <td>
                                    <if condition="$x eq 0">
                                        <input type="text" class="form-control js-date" name="whq_start_date" autocomplete="off"
                                           value="{$whq_start_date}"
                                           style="width: 105px">
                                    </if>
                                </td>
                                <td><input type="text" class="form-control js-datetime" name="funeral_time[]" autocomplete="off"
                                           value="{$vo.funeral_time}"
                                           style="width: 168px"></td>
                                <td>
                                    <select name="convergence_type[]" class="form-control">
                                        <option value="1"
                                        <if condition="$vo.convergence_type eq 1">selected</if>
                                        >骨灰</option>
                                        <option value="2"
                                        <if condition="$vo.convergence_type eq 2">selected</if>
                                        >骨殖</option>
                                    </select>
                                    <input name="receptionist[]" value="" type="hidden">
                                </td>
                                <td><select name="type[]" class="form-control" style="width: 120px">
                                    <option value="">请选择</option>
                                    <option value="1"
                                    <if condition="$vo.type eq 1">selected</if>
                                    >首位安葬</option>
                                    <option value="2"
                                    <if condition="$vo.type eq 2">selected</if>
                                    >合葬</option>
                                </select>
                                </td>
                                <!--<td>-->
                                    <!--<select name="receptionist[]" class="form-control">-->
                                        <!--<volist name="deptPer" id="v">-->
                                            <!--<option value="{$v.id}"-->
                                            <!--<if condition="$vo.receptionist eq $v.id">selected</if>-->
                                            <!--&gt;{$v.department_name}-{$v.user_nickname}</option>-->
                                        <!--</volist>-->
                                    <!--</select>-->
                                <!--</td>-->
                                <td><input type="text" class="form-control" name="relationship_users[]"
                                           value="{$vo.relationship_users}"
                                           style="width: 160px"></td>
                                <td>
                                    <php>$img_cer=cmf_get_image_preview_url(isset($vo['cremation_certificate'])?$vo['cremation_certificate']:'');</php>
                                    <input type="hidden" name="cremation_certificate_file_id[]" id="thumb-file_id" value="{$vo.cremation_certificate_file_id|default=''}">
                                    <input type="hidden" name="cremation_certificate[]" id="thumb" value="{$vo.cremation_certificate|default=''}">
                                    <a href="javascript:gpyUploadOneImage('图片上传','#thumb','{$tomb_num}');">
                                        <h5 class="btn btn-primary">拍照上传</h5>
                                    </a>
                                    <img src="{$img_cer}" onclick="parent.imagePreviewDialog(this.src);"  id="thumb-preview" style="cursor: pointer; width: 50px"/>
                                </td>
                            </tr>
                        </foreach>
                    </empty>
                    </tbody>
                </table>
                <!--<div class="btn btn-primary" id="">添加碑文</div>-->
            </div>
            </if>
        </fieldset>
        <div class="form-actions">

            <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
            <a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js?v={:time()}"></script>
<script type="text/javascript" src="__STATIC__/js/layer/layer.js"></script>
<script type="text/javascript">

    function closing_price(obj) {
        //先把非数字的都替换掉，除了数字和.
        obj.value = obj.value.replace(/[^\d.]/g, "");
        //必须保证第一个为数字而不是.
        obj.value = obj.value.replace(/^\./g, "");
        //保证只有出现一个.而没有多个.
        obj.value = obj.value.replace(/\.{2,}/g, ".");
        //保证.只出现一次，而不能出现两次以上
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        //保证 数字整数位不大于8位
        if (100000000 <= parseFloat(obj.value))
            obj.value = "";
    }
    $('.free_price').blur(function () {
        var tomb_type = $("#tomb_type").val();
        var free_price  = $(this).val();
        if(0 >free_price ){
            layer.msg('免零金额不能小于0元');
        }else {
            var selling_price = $('.selling_price').val();
            if(tomb_type == 2){
                var subscription_area = $('.subscription_area').val();
                if(subscription_area == null || subscription_area == 0 ){
                    layer.msg('请输入认购面积！');
                }else{
                    var receivable_price = Number(
                        ((Number($('.selling_price').val().replace(/,/g, "")).toFixed(2)*1 ) * Number(subscription_area))-
                        Number(free_price.replace(/,/g,"")).toFixed(2)*1
                    );
                    $(".closing_price").val(receivable_price.toFixed(2));
                }
            }else{
                var receivable_price = Number(
                    ((Number($('.selling_price').val().replace(/,/g, "")).toFixed(2)*1 ))-
                    Number(free_price.replace(/,/g,"")).toFixed(2)*1
                );
                $(".closing_price").val(receivable_price.toFixed(2));
            }


        }
    })
    $('.closing_price').blur(function () {
        var tomb_type = $("#tomb_type").val();
        var closing_price  = $(this).val();
        if(0 >closing_price ){
            layer.msg('成交金额不能小于0元');
        }else {
            var selling_price = $('.selling_price').val();
            if(tomb_type == 2){
                var subscription_area = $('.subscription_area').val();
                if(subscription_area == null || subscription_area == 0 ){
                    layer.msg('请输入认购面积！');
                }else{
                    var receivable_price = Number(
                        ((Number($('.selling_price').val().replace(/,/g, "")).toFixed(2)*1 ) * Number(subscription_area.replace(/,/g,"")).toFixed(2)*1)-
                        Number(closing_price.replace(/,/g,"")).toFixed(2)*1
                    );
                    $(".free_price").val(receivable_price.toFixed(2));
                }
            }else{
                var receivable_price = Number(
                    ((Number($('.selling_price').val().replace(/,/g, "")).toFixed(2)*1 ))-
                    Number(closing_price.replace(/,/g,"")).toFixed(2)*1
                );
                $(".free_price").val(receivable_price.toFixed(2));
            }
        }
    })
    $('.subscription_area').blur(function () {
        var subscription_area  = $(this).val();
        if(0 >subscription_area ){
            layer.msg('认购面积不能小于0');
        }else {
            var free_price  = $('.free_price').val();

            var receivable_price = Number(
                ((Number($('.selling_price').val().replace(/,/g, "")).toFixed(2)*1 ) * Number(subscription_area))-
                Number(free_price.replace(/,/g,"")).toFixed(2)*1
            );
            $(".closing_price").val(receivable_price.toFixed(2));

        }
    })
</script>
</body>
</html>